package com.servlet.news;

import com.dao.NewsDao;
import com.dao.NewsInfo;
import com.dao.UserInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author admin
 */
@WebServlet(name = "NewsDeleteServlet",urlPatterns = "/NewsDeleteServlet.filter")
public class NewsDeleteServlet extends HttpServlet {
    private NewsDao newsDao = new NewsInfo();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String n_id = request.getParameter("n_id");
        try {
            boolean b = newsDao.deleteNews(Integer.parseInt(n_id));
            if (b){
                System.out.println("新闻删除成功");
                response.sendRedirect(request.getContextPath()+"/NewsSelectAllServlet.filter");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
